<template>
  <view class="home_tab">
    <view class="home_tab_title">
      <view class="home_tab_inner">
        <uni-segmented-control
          :current="current"
          :values="items.map((item) => item.title)"
          @clickItem="onClickItem"
          style-type="text"
          active-color="#42a5f5"
        ></uni-segmented-control>
      </view>
      <view class="iconfont iconsearch"></view>
    </view>
    <view class="home_tab_content">
      <view v-if="current === 0">
        <home-recommend></home-recommend>
      </view>
      <view v-if="current === 1">
        <home-category></home-category>
      </view>
      <view v-if="current === 2">
        <home-new></home-new>
      </view>
      <view v-if="current === 3">
        <home-album></home-album>
      </view>
    </view>
  </view>
</template>

<script>
import homeRecommend from "./home-recommend";
import homeCategory from "./home-category";
import homeNew from "./home-new";
import homeAlbum from "./home-album";
import { uniSegmentedControl } from "@dcloudio/uni-ui"; // 导入 uni-ui 的分段器
export default {
  /* 数据源 */
  data() {
    return {
      items: [
        { title: "推荐" },
        { title: "分类" },
        { title: "最新" },
        { title: "专辑" },
      ],
      current: 0,
    };
  },
  /* 方法集合 */
  methods: {
    onClickItem(e) {
      // console.log("debug => ",e)
      if (this.current !== e.currentIndex) {
        this.current = e.currentIndex;
      }
    },
  },
  /* 注册引入的组件 */
  components: {
    homeRecommend,
    homeCategory,
    homeNew,
    homeAlbum,
    uniSegmentedControl,
  },
  /* 页面生命周期函数，监听页面加载 */
  onLoad() {
      this.request({
          url: "http://157.122.54.189:9088/image/v1/vertical/category"
      })
      .then((res) => {
          // console.log(res);
      })
  },
};
</script>

<style lang="scss">
.home_tab {
  .home_tab_title {
    position: relative; // relative 相对定位
    .home_tab_inner {
        width: 60%;
        margin: 0 auto; // 水平居中
    }
    .iconsearch{
        position: absolute; // absolute 绝对定位
        top: 50%;
        transform: translateY(-50%);
        right: 5%;
    }
  }
  .home_tab_content {
  }
}
</style>